﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace Zocono.WCS.Admin.Models.ConfigManager
{
    public class PlcConnectionInfoDto
    {
        public long ID { get; set; }
        public string Js_Id { get { return ID.ToString(); } }
        public string IP { get; set; }
        public int PlcCpuType { get; set; }
        public short Rack { get; set; }
        public short Slot { get; set; }
        public bool IsSc { get; set; }
        public string ScEquipmentCode { get; set; }
        public string PlcCpuTypeFormat
        {
            get
            {
                var result = this.PlcCpuType.ToString();
                var item = S7CpuTypeItem.S7CpuTypeDatasource.FirstOrDefault(c => c.CpuTypeValue == this.PlcCpuType);
                if (item != null)
                {
                    result = item.CpuTypeName;
                }

                return result;
            }
        }

        public string IsScFormat
        {
            get
            {
                var result = this.IsSc.ToString();
                var item = IsScItem.IsScItemDatasource.FirstOrDefault(c => c.IsScValue == (this.IsSc ? 1 : 0));
                if (item != null)
                {
                    result = item.IsScName;
                }

                return result;
            }
        }
    }

    public class PlcConnectionInfoPageData
    {
        public long ID { get; set; }
        public string Js_Id { get { return ID.ToString(); } }
        public string IP { get; set; }
        public int PlcCpuType { get; set; }
        public short Rack { get; set; }
        public short Slot { get; set; }
        public bool IsSc { get; set; }
        public string ScEquipmentCode { get; set; }

        public List<IsScItem> IsScItems { set; get; }

        public List<S7CpuTypeItem> S7CpuTypes { get; set; }
    }

    public class PlcConnectionInfoFliterPageData
    {
        public List<IsScItem> IsScItems { set; get; }

        public List<S7CpuTypeItem> S7CpuTypes { get; set; }
    }


    public class PlcConnectionLockInfoPageData
    {
        public long ID { get; set; }
        public string Js_Id { get { return ID.ToString(); } }
        /// <summary>
        /// plc连接关联Id
        /// </summary>
        public long PlcConnectionID { get; set; }
        /// <summary>
        /// 进程编号
        /// </summary>
        public string ProgrameCode { get; set; }
        /// <summary>
        /// 任务名称
        /// </summary>
        public string JobName { get; set; }
        /// <summary>
        /// 是否锁定
        /// </summary>
        public bool IsLock { get; set; }
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateTime { get; set; }
        /// <summary>
        /// plc ip
        /// </summary>
        [Required(AllowEmptyStrings = true)]
        public string PlcConnectionIP { get; set; }
        /// <summary>
        /// plc cpu
        /// </summary>
        [Required(AllowEmptyStrings = true)]
        public string PlcCpuType { get; set; }

        public string PlcCpuTypeFormat
        {
            get
            {
                var result = this.PlcCpuType.ToString();
                var item = S7CpuTypeItem.S7CpuTypeDatasource.FirstOrDefault(c => c.CpuTypeValue + "" == this.PlcCpuType);
                if (item != null)
                {
                    result = item.CpuTypeName;
                }

                return result;
            }
        }
    }

    /// <summary>
    /// plc连接状态信息
    /// </summary>
    public class PlcConnectionStateInfoPageData
    {
        public long ID { get; set; }
        public string Js_Id { get { return ID.ToString(); } }
        /// <summary>
        /// plc连接关联Id
        /// </summary>
        public long PlcConnectionID { get; set; }
        /// <summary>
        /// 进程编号
        /// </summary>
        public string ProgrameCode { get; set; }
        /// <summary>
        /// 连接状态
        /// </summary>
        public bool Connected { get; set; }
        public DateTime UpdateTime { get; set; }
        /// <summary>
        /// plc ip
        /// </summary>
        [Required(AllowEmptyStrings = true)]
        public string PlcConnectionIP { get; set; }
        /// <summary>
        /// plc cpu
        /// </summary>
        [Required(AllowEmptyStrings = true)]
        public string PlcCpuType { get; set; }

        public string PlcCpuTypeFormat
        {
            get
            {
                var result = this.PlcCpuType.ToString();
                var item = S7CpuTypeItem.S7CpuTypeDatasource.FirstOrDefault(c => c.CpuTypeValue + "" == this.PlcCpuType);
                if (item != null)
                {
                    result = item.CpuTypeName;
                }

                return result;
            }
        }
    }
}
